﻿using System;
using System.Globalization;
using System.Text;
using System.Web;
using EPiServer.Configuration;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.Municipality.Extensions;
using EPiServer.Municipality.Web.UI;

namespace EPiServer.Municipality.Templates.MasterPages
{
    public partial class Mobile : MasterPageBase
    {

        #region protected string PageTitle
        /// <summary>
        /// Gets the PageTitle of the Default
        /// </summary>
        /// <value></value>
        protected string PageTitle
        {
            get
            {
                return PageReference.StartPage.CompareToIgnoreWorkID(CurrentPage.PageLink) ?
                    string.Format("{0} - {1}", Settings.Instance.SiteDisplayName, CurrentPage.PropertyValueWithDefault("Heading", CurrentPage.PageName)) :
                    string.Format("{0} - {1}", CurrentPage.PropertyValueWithDefault("Heading", CurrentPage.PageName), Settings.Instance.SiteDisplayName);
            }
        }
        #endregion

        public string BackLink
        {
            get { return DataFactory.Instance.GetPage(CurrentPage.ParentLink).LinkURL; }
        }

        public string HomeLink
        {
            get
            {
                var MobileStart = DataFactory.Instance.GetPage((PageReference)CurrentPage["MobileStart"]);
                return MobileStart.LinkURL;
            }
        }

        public string TwitterLink
        {
            get
            {
                if (CurrentPage.IsValue("Twitter"))
                    return String.Format("<a href=\"{1}\" target='_blank' rel='external'><img alt=\"{0}\" src=\"/Images/MobileImages/Icons/black/twitter.png\" /></a>", "Twitter", CurrentPage["Twitter"]);

                return String.Empty;
            }
        }

        public string RssLink
        {
            get
            {
                if (CurrentPage.IsValue("Rss"))
                {
                    var pRef = CurrentPage["Rss"] as PageReference;
                    if (pRef != null)
                    {
                        var page = DataFactory.Instance.GetPage((PageReference)CurrentPage["Rss"]);
                        return String.Format("<a href=\"{1}\" target='_blank' rel='external'><img alt=\"{0}\" src=\"/Images/MobileImages/Icons/black/rss-basic.png\" /></a>", "Rss", page.LinkURL);
                    }
                }

                return String.Empty;
            }
        }

        public string FacebookLink
        {
            get
            {
                if (CurrentPage.IsValue("Facebook"))
                    return String.Format("<a href=\"{1}\" target='_blank' rel='external'><img alt=\"{0}\" src=\"/Images/MobileImages/Icons/black/facebook-logo.png\" /></a>", "Facebook", CurrentPage["Facebook"]);



                return String.Empty;
            }
        }

        public string MainStart
        {
            get
            {
                if (CurrentPage.IsValue("MainStart"))
                    return String.Format("<a href=\"{0}\" target='_blank' rel='external'>{1}</a>", CurrentPage["MainStart"], CurrentPage["MainStartText"]);
                return String.Empty;
            }
        }



    }
}


//using System;
//using System.Globalization;
//using System.Text;
//using System.Web;
//using EPiServer.Configuration;
//using EPiServer.Core;
//using EPiServer.DataAbstraction;
//using EPiServer.Municipality.Extensions;
//using EPiServer.Municipality.Web.UI;

//namespace EPiServer.Municipality.Templates.MasterPages {
//    public partial class Mobile : MasterPageBase {

//        #region protected string PageTitle
//        /// <summary>
//        /// Gets the PageTitle of the Default
//        /// </summary>
//        /// <value></value>
//        protected string PageTitle
//        {
//            get
//            {
//                return PageReference.StartPage.CompareToIgnoreWorkID(CurrentPage.PageLink) ?
//                    string.Format("{0} - {1}", Settings.Instance.SiteDisplayName, CurrentPage.PropertyValueWithDefault("Heading", CurrentPage.PageName)) :
//                    string.Format("{0} - {1}", CurrentPage.PropertyValueWithDefault("Heading", CurrentPage.PageName), Settings.Instance.SiteDisplayName);
//            }
//        }
//        #endregion

//        public string BackLink {
//            get { return DataFactory.Instance.GetPage(CurrentPage.ParentLink).LinkURL; }
//        }

//        public string HomeLink {
//            get
//            {

                
                
//                var property = DynamicProperty.Load(CurrentPage.PageLink, "MobileStart");
//                var mobileStart = DataFactory.Instance.GetPage(property.PropertyValue.Value as PageReference);
//                return mobileStart.LinkURL;
//            }
//        }
       
//        public string TwitterLink {
//            get
//            {
//                var property = DynamicProperty.Load(CurrentPage.PageLink, "Twitter");
//                if (property != null){
//                    var pRef = property.PropertyValue.Value as PageReference;
//                    if (pRef != null){
//                        return String.Format("<a href=\"{1}\" target='_blank' rel='external'><img alt=\"{0}\" src=\"/Documents/MobileImages/Icons/black/twitter.png\" /></a>","Twitter", pRef);
//                    }
//                }
//                return String.Empty;
//            }
//        }

//        public string RssLink
//        {
//            get
//            {
//                var property = DynamicProperty.Load(CurrentPage.PageLink, "Rss");
//                if(property != null){
//                    var pRef = property.PropertyValue.Value as PageReference;
//                    if (pRef != null)
//                    {
//                        var page = DataFactory.Instance.GetPage(pRef);
//                        return String.Format("<a href=\"{1}\" target='_blank' rel='external'><img alt=\"{0}\" src=\"/Documents/MobileImages/Icons/black/rss-basic.png\" /></a>", "Rss", page.LinkURL);
//                    }
//                }
//                return String.Empty;
//            }
//        }

//        public string FacebookLink
//        {
//            get
//            {
//                var property = DynamicProperty.Load(CurrentPage.PageLink, "Facebook");
//                if (property != null){
//                    var pRef = property.PropertyValue.Value as PageReference;
//                    if (pRef != null){
//                        return String.Format("<a href=\"{1}\" target='_blank' rel='external'><img alt=\"{0}\" src=\"/Documents/MobileImages/Icons/black/facebook-logo.png\" /></a>","Facebook", pRef);
//                    }
//                }
//                return String.Empty;
//            }
//        }

//        public string MainStart
//        {
//            get
//            {
//                var propertyMainStart = DynamicProperty.Load(CurrentPage.PageLink, "MainStart");
//                var propertyMainStartText = DynamicProperty.Load(CurrentPage.PageLink, "MainStartText");
//                if (propertyMainStart != null && propertyMainStartText != null){
//                    return String.Format("<a href=\"{0}\" target='_blank' rel='external'>{1}</a>", propertyMainStart.PropertyValue.Value, propertyMainStartText.PropertyValue.Value);
//                }
//                return String.Empty;
//            }
//        }
//    }
//}